package com.zhenxiang.juc.lock.lock8;

import java.util.concurrent.TimeUnit;

/**
 * @Author : James
 * @Create : 2021-12-21-14:50
 * @Description :
 */
public class Test2 {
    public static void main(String[] args) {
       Phone2 phone = new Phone2();
       Phone2 phone2 = new Phone2();
       new Thread(()->{
           phone.sendSms();
       },"A").start();

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        new Thread(()->{
           phone.call();
       },"B").start();

        new Thread(()->{
            phone2.hello();
        },"C").start();

    }
}


class Phone2 {

    public  synchronized void sendSms()  {
        try {
            TimeUnit.SECONDS.sleep(4);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("发短信");

    }

    public synchronized void call(){
        System.out.println("打电话");
    }

    public void hello (){
        System.out.println("Hello");
    }
}
